package mr.go.yaxc.tests.test3;

import java.util.LinkedList;
import mr.go.yaxc.Action;
import mr.go.yaxc.ScopeHandler;
import mr.go.yaxc.tests.test3.Appender;
import mr.go.yaxc.tests.test3.Logger;
import mr.go.yaxc.tests.test3.LoggerFactory;
import org.xml.sax.Attributes;

public class RootLoggerAction extends Action {

    private Logger rootLogger;

    @Override
    public void carryOut(String name, Attributes attributes,
                         ScopeHandler handler)
            throws Exception {
        rootLogger = LoggerFactory.getRootLogger();
        final String level = attributes.getValue(getAttribute("level"));
        if (level != null) {
            rootLogger.setLevel(level);
        }
        object = rootLogger;
        params = new LinkedList<Object>();
    }

    @Override
    public void processed(String body, ScopeHandler handler)
            throws Exception {
        for (Object param : params) {
            rootLogger.setAppender((Appender) param);
        }
    }
}
